﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using OgilvyOne.Model;
using OgilvyOne.DALFactory;

namespace OgilvyOne.BLL
{
    public class CmsArticleImgsBll
    {
        public int Add(CmsArticleImgModel model)
        {
            return CmsArticleImgsFactory.create().Add(model);
        }
        public bool Update(CmsArticleImgModel model)
        {
            return CmsArticleImgsFactory.create().Update(model);
        }
        public CmsArticleImgModel GetImgModel(int iid)
        {
            return CmsArticleImgsFactory.create().GetImgModel(iid);
        }
        /// <summary>
        /// 查询文章图片
        /// </summary>
        /// <param name="q">q.articleId 文章ID</param>
        /// <returns></returns>
        public IList GetImgsList(CmsArticleImgModel q)
        {
            return CmsArticleImgsFactory.create().GetImgsList(q);
        }

        public bool Delete(int iid)
        {
            return CmsArticleImgsFactory.create().Delete(iid);
        }

        /// <summary>
        /// 修改排序号
        /// </summary>
        /// <param name="aid"></param>
        /// <param name="next">0 上 1 下</param>
        /// <returns>修改排序号</returns>
        public int ModOrderNum(int id, int next)
        {
            CmsArticleImgModel cm = GetImgModel(id);
            int ordernum = cm.ImgOrder;
            int temcmid = CmsArticleImgsFactory.create().GetOrderImgsId(cm.ArticleId, ordernum, next);
            if (temcmid > 0)
            {
                CmsArticleImgModel temcm = GetImgModel(temcmid);
                CmsArticleImgsFactory.create().ModOrderNum(id, temcm.ImgOrder);
                CmsArticleImgsFactory.create().ModOrderNum(temcm.ImgsId, ordernum);

                return temcm.ImgOrder;
            }
            return 0;

        }

        /// <summary>
        /// 栏目最大排序号
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public int MaxOrder(int aid)
        {
            return CmsArticleImgsFactory.create().MaxOrder(aid);
        }
    }
}
